<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>编辑影院</span>
      </div>

      <From :form="form" @getInfo="getInfo" :cinema="cinema">
        <el-form-item>
          <el-button type="primary" @click="onSubmit"  :loading="loading">提交</el-button>
          <!-- <el-button>取消</el-button> -->
        </el-form-item>
      </From>
    </el-card>
  </div>
</template>

<script>
import From from "./From";
export default {
  data() {
    return {
      //存放表单数据
       loading: false,
      cinema: {},
      form: {
        cityId: "",
        cinemaId: "",
        areaId: "",
        name: "",
        address: "",
        lowPrice: "",
        areaName: "",
        cityName: ""
      }
    };
  },
  created() {
    this.getDetail();
  },
  components: {
    From
  },
  methods: {
    async getDetail() {
      let cinemaId = this.$route.params.cinemaId;

      let url = "/cinema/getDetail" + `?cinemaId=${cinemaId}`;
      let u = "/cinema/getDetail";
      let res = await this.$axios.post(u, { cinemaId });
      this.form = res.cinema;

      //解构对象
      let { cityId, areaName } = res.cinema;
      console.log(res.cinema);
      //解构信息
      this.cinema = {
        cityId,
        areaName
      };
    },

    async onSubmit() {
      let url = "/cinema/edit";

       try {
        this.loading=true
        let data = this.form;
        let res = await this.$axios.post(url, data);
        this.$message({
          message: "编辑影院成功",
          type: "success"
        });
      } catch (error) {}
      this.loading = false;   

    },
    getInfo(data) {
      this.form = {
        ...this.form,
        ...data
      };
    }
  }
};
</script>
<style>
.fond {
  font-size: 13.5px;
}
</style>